<template>
  <div class="page-chargeDetails">
    <div v-if="showFlag">
      <div class="c-header">
        <h2>{{['','未支付','充电中','充电结束','已过期'][orderInfo.state]}}</h2>
        <div class="c-car"></div>
      </div>

      <div class="c-site-info">
          <div class="s-img">站点<br />信息</div>
          <div class="s-name">{{orderInfo.plug.site.name}}</div>
          <div class="s-addr">{{orderInfo.plug.site.area}}{{orderInfo.plug.site.address}}</div>
      </div>

      <div class="c-content">
        <div class="c-item">
          <label>消费金额：</label>
          <div class="c-inner">{{(orderInfo.amount/100).toFixed(2)}}元</div>
        </div>
        <div class="c-item">
          <label>充电时长：</label>
          <div class="c-inner">{{orderInfo.actualTimespan}}</div>
        </div>
        <div class="c-item">
          <label>开始时间：</label>
          <div class="c-inner">{{orderInfo.beginTime}}</div>
        </div>
        <div v-if="orderInfo.state==3" class="c-item">
          <label>结束时间：</label>
          <div class="c-inner">2017-10-21 13:00</div>
        </div>
        <div class="c-item">
          <label>订单编号：</label>
          <div class="c-inner">{{orderInfo.orderNumber}}</div>
        </div>
      </div>
    </div>
  </div>
</template>



<style lang="less" scoped>
.page-chargeDetails {
  width: 100%;
  height: 100%;
  background: #f2f2f5;
}

.c-img {
  position: relative;
  text-align: center;
  box-sizing: border-box;
  padding-top: 120px;
  img {
    position: absolute;
    left: 50%;
    width: 328px;
    height: 328px;
    transform: translate(-50%, 0);
    z-index: 1000;
  }
  div {
    position: absolute;
    left: 50%;
    width: 128px;
    height: 250px;
    transform: translate(-50%, 20%);
    background: #ffff00;
    /* background: #ffdf5d; */
    animation: s 1.5s linear infinite;
  }
}

@keyframes s {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

// 头部
.c-header {
  width: 100%;
  // background:linear-gradient(#8CD6A3,#40BB6B);
  background-image: linear-gradient(45deg, #2fc1ff, #2993ec);
  border-bottom: 1px solid #ececec;
  display: -webkit-box;
  box-sizing: border-box;
  height: 190px;
  box-sizing: border-box;
  padding: 0 60px;

  h2 {
    -webkit-box-flex: 1;
    text-align: right;
    display: -webkit-box;
    -webkit-box-align: center;
    -webkit-box-pack: start;
    font-size: 32px;
    color: #fff;
    font-weight: normal;
  }
  .c-car {
    width: 200px;
    height: 190px;
    -webkit-box-flex: 1;
    background: url("../public/imgs/icon-d-car.svg") 80% 55% no-repeat;
    background-size: 180px 152px;
  }
}

// 站点信息
.c-site-info {
  position: relative;
  height: 180px;
  box-sizing: border-box;
  padding: 40px 70px 40px 150px;
  background: #fff;
  margin: 0 0 20px 0;
  .s-img {
    position: absolute;
    left: 35px;
    top: 50%;
    transform: translate(0, -50%);
    width: 95px;
    height: 95px;
    border-radius: 50%;
    border: 4px solid #2992ed;
    text-align: center;
    line-height: 30px;
    font-size: 22px;
    box-sizing: border-box;
    padding: 15px 0 0 0;
  }
  .s-name {
    font-size: 30px;
    line-height: 45px;
    height: 50px;
    color: #000;
  }
  .s-addr {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
}

// 内容部分
.c-content {
  background: #fff;
  width: 100%;
  box-sizing: border-box;
  padding: 30px;
  font-size: 26px;
  color: #333;
  margin: 0 0 20px 0;

  .c-item {
    display: -webkit-box;
    height: 50px;
    line-height: 50px;
    label {
      display: block;
      width: 150px;
      -webkit-box-align: center;
      -webkit-box-pack: start;
    }
    .c-inner {
      -webkit-box-flex: 1;
    }
  }
}
</style>


<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      showFlag: false,
      orderInfo: {}
    };
  },
  mounted() {
    var self = this;
    var id = self.$route.query.id;
    if (id != undefined) {
      this.init(id);
    } else {
      this.Toast("订单ID参数错误~");
    }
  },
  methods: {
    init(id) {
      var self = this;
      var req = this.Axios.get(this.Interface.host, {
        params: self.GetQuerys({
          id: id
        })
      });
      // 请求数据
      req.then(res => {
        var data = res.data.data.me;
        if (data != null) {
          self.showFlag = true;
          self.orderInfo = data.order;
        }
      });
      // 请求接口失败
      req.catch(res => {
        this.Toast("服务器开小差了~");
      });
    },
    GetQuerys({ id }) {
      return {
        query: `{
                  me {
                    order(id:${id}) {
                      orderNumber
                      beginTime
                      created_at
                      amount
                      state
                      timespan
                      actualTimespan
                      plug {
                        site {
                          name
                          area
                          address
                        }
                      }
                    }
                  }
                }`
      };
    }
  }
};
</script>
